package com.desheng.bigdata.ds.graph;

import com.desheng.bigdata.ds.queue.Queue;

/**
 * @Description 无向图
 * @Author deshenglijun
 * @Date 2020/6/3 22:07
 * @Version 1.0
 */
public class Graph {
    private int vertex;
    private int edges;

    private Queue<Integer>[] queues;

    public Graph(int vertex) {
        this.vertex = vertex;
        this.edges = 0;
        queues = new Queue[vertex];
        for (int i = 0; i < queues.length; i++) {
            queues[i] = new Queue<Integer>();
        }
    }

    public int vertex() {
        return this.vertex;
    }
    public int edges() {
        return this.edges;
    }

    //将顶点w和v添加一条边
    public void addEdge(int v, int w) {
        queues[v].enqueue(w);
        queues[w].enqueue(v);
        edges++;
    }

    public Queue<Integer> adj(int w) {
        return queues[w];
    }
}
